package com.licode.codekit.utils;

import javax.swing.*;
import java.awt.*;

public class UIBuilderUtil {
    private int LABEL_WID = 120;
    public UIBuilderUtil() {

    }

    public UIBuilderUtil(int wid) {
        LABEL_WID = wid;
    }

    public JComponent buildRow(Component left, Component c, Component right) {
        return this.buildRow(LABEL_WID, left, c, right);
    }

    public JComponent buildRow(int wid, Component left, Component c, Component right) {
        JPanel panel = new JPanel(new BorderLayout());
        left.setPreferredSize(new Dimension(wid, 0));
        left.setMinimumSize(new Dimension(wid, 0));
        panel.add(left, "West");
        panel.add(c, "Center");
        panel.add(right, "East");
        return panel;
    }

    public JComponent buildFillRow(Component left, Component right) {
        return buildFillRow(LABEL_WID, left, right);
    }

    public JComponent buildFillRow(int leftWid, Component left, Component right) {
        JPanel panel = new JPanel(new BorderLayout(0, 0));

        if (leftWid > 0) {
            left.setPreferredSize(new Dimension(leftWid, 0));
            left.setMinimumSize(new Dimension(leftWid, 0));
        }

        panel.add(left, BorderLayout.WEST);
        panel.add(right, BorderLayout.CENTER);
        return panel;
    }

    public JComponent buildTwoCol(Component left, Component right) {
        GridLayout layGrid = new GridLayout(1, 2);
        JPanel panel = new JPanel(layGrid);

        panel.add(left);
        panel.add(right);
        return panel;
    }

    public JComponent buildRow(Component c1, Component c2, Component c3, Component c4) {
        Box row = Box.createHorizontalBox();

        c1.setPreferredSize(new Dimension(LABEL_WID, 0));
        c1.setMinimumSize(new Dimension(LABEL_WID, 0));

        row.add(c1);
        row.add(c2);
        row.add(c3);
        row.add(c4);
        return row;
    }
}
